﻿using System;
using System.Collections.Generic;
using BotonJXC.Entity;
using NHibernate.Criterion;
using BotonJXC.Util;

namespace BotonJXC.DAO
{
    public class InventoryBackupDAO : NHibernateDao<InventoryBackup, int>
    {
        public PageModel<InventoryBackup> Find(int typeId, int supplierId, int warehouseId, string cargoSpace, int start, int count)
        {
            List<ICriterion> criterions = new List<ICriterion>();

            if (typeId > 0)
            {
                criterions.Add(Restrictions.Eq("ProType.TypeId", typeId));
            }
            if (supplierId > 0)
            {
                criterions.Add(Restrictions.Eq("Supplier.SupplierId", supplierId));
            }
            if (warehouseId > 0)
            {
                criterions.Add(Restrictions.Eq("Warehouse.WarehouseId", warehouseId));
            }
            if (!string.IsNullOrEmpty(cargoSpace))
            {
                criterions.Add(Restrictions.Eq("CargoSpace", cargoSpace));
            }
            return base.FindByPage(criterions.ToArray(), null, start, count);
        }
    }
}